function search() {
    const query = document.getElementById('searchInput').value;
    if (!query.trim()) return;

    // 修改为正确的接口路由
    fetch(`/api/query?query=MATCH (n:CulturalItem) WHERE n.name CONTAINS '${query}' RETURN n`)
        .then(response => response.json())
        .then(function(data) {
            if (!data.success) {
                alert(data.message);
                return;
            }

            switchContent('graph');
            
            const detailsContent = document.getElementById('detailsContent');
            detailsContent.innerHTML = '<h4 class="mb-4">搜索结果</h4>';
            
            // 修改数据处理逻辑以匹配返回格式
            data.data.forEach(item => {
                const properties = item.n;  // 根据查询返回的结构调整
                const div = document.createElement('div');
                div.innerHTML = `
                    <div class="p-4 bg-white rounded-lg shadow mb-3">
                        <h3 class="text-xl font-bold mb-2">${properties.name}</h3>
                        <p class="text-gray-700">${properties.description || '暂无描述'}</p>
                    </div>
                `;
                detailsContent.appendChild(div);
            });
        })
        .catch(error => {
            console.error('搜索出错:', error);
            alert('搜索过程中出现错误，请稍后重试');
        });
}

// 为搜索框添加回车事件监听
document.getElementById('searchInput').addEventListener('keypress', function(e) {
    if (e.key === 'Enter') {
        e.preventDefault();
        search();
    }
});